package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsNarratorDetail;
import com.macro.mall.dto.BmsNarratorParam;
import com.macro.mall.dto.BmsNarratorParam;
import com.macro.mall.model.BmsNarrator;
import com.macro.mall.model.BmsTourismProject;
import com.macro.mall.service.BmsNarratorService;
import com.macro.mall.service.BmsTourismProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(tags = "BmsNarratorController")
@Tag(name = "BmsNarratorController", description = "讲解项目")
@RequestMapping("/narratorProject")
public class BmsNarratorController {

    @Autowired
    private BmsNarratorService bmsNarratorService;

    @ApiOperation("分页查询讲解项目")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsNarrator>> getList(@RequestBody BmsNarratorParam bmsNarratorParam) {
        List<BmsNarrator> bmsNarratorList = bmsNarratorService.getList(bmsNarratorParam);
        return CommonResult.success(CommonPage.restPage(bmsNarratorList));
    }

    @ApiOperation("添加讲解项目")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsNarratorParam bmsNarratorParam) {
        int count = bmsNarratorService.create(bmsNarratorParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改讲解项目")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsNarratorParam bmsNarratorParam) {
        int count = bmsNarratorService.update(bmsNarratorParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("根据id获取讲解项目信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsNarratorDetail> getItem(@PathVariable Long id) {
        BmsNarratorDetail bmsNarratorDetail = bmsNarratorService.getItem(id);
        return CommonResult.success(bmsNarratorDetail);
    }

    @ApiOperation("删除讲解项目")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsNarratorService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
